package Com.javaserver.servlet;

import Com.javaserver.bean.staff;
import Com.javaserver.dao.staffserver;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/stadele")
public class staffDeleteserverlet extends HttpServlet {
            staffserver staff=new staffserver();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setCharacterEncoding("UTF-8");
        String stadele=req.getParameter("delete");
          staff sta=new staff();
          sta.setA_id(stadele);
          if (staff.stadele(sta) == false){
              List<staff> list = staff.stalist(1);
              req.getSession().setAttribute("staflist", list);
              req.getSession().setAttribute("msg", "删除失败");
              resp.sendRedirect(req.getContextPath() + "/StaffManagement.jsp");
          }else {
              List<staff> list = staff.stalist(1);
              req.getSession().setAttribute("staflist", list);
              req.getSession().setAttribute("msg", "删除成功");
              resp.sendRedirect(req.getContextPath() + "/stalist");
          }

    }
}
